package com.tanhua.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.api.SoulRecordApi;
import com.tanhua.db.mapper.SoulRecordMapper;
import com.tanhua.model.soul.SoulRecord;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;

import javax.swing.*;
import java.util.List;

@DubboService
public class SoulRecordApiImpl implements SoulRecordApi {


    @Autowired
    private SoulRecordMapper soulRecordMapper;

    @Override
    public String saveSoulRecord(SoulRecord soulRecord) {
        soulRecordMapper.insert(soulRecord);
        return soulRecord.getId().toString();
    }

    @Override
    public SoulRecord getRecentRecord(Integer askId, Long userId) {
        LambdaQueryWrapper<SoulRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SoulRecord::getQuestionPageId, askId);
        wrapper.eq(SoulRecord::getUserId, userId);
        wrapper.orderByDesc(SoulRecord::getCreated);
        wrapper.last("limit 1");
        SoulRecord soulRecord = soulRecordMapper.selectOne(wrapper);
        return soulRecord;
    }

    @Override
    public SoulRecord selectById(Long id) {
        SoulRecord record = soulRecordMapper.selectById(id);
        return record;
    }

    //按照id排除自己,查询是否存在推荐用户数据
    @Override
    public List<SoulRecord> selectByScore(Long id, Integer recordScore, Integer questionPageId) {
        LambdaQueryWrapper<SoulRecord> qw = new LambdaQueryWrapper();
        qw.ne(SoulRecord::getId,id);
        qw.eq(SoulRecord::getRecordScore,recordScore);
        qw.eq(SoulRecord::getQuestionPageId,questionPageId);
        List<SoulRecord> list = soulRecordMapper.selectList(qw);
        return list;
    }




}
